package com.cpos.bkge.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpos.bkge.base.ResultInfo;
import com.cpos.bkge.entity.CposBkUser;
import com.cpos.bkge.mapper.CposBkUserMapper;
import com.cpos.bkge.service.CposBkUserService;
import com.cpos.bkge.service.ICposBkUserService;
import org.apache.tomcat.util.security.MD5Encoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.security.provider.MD5;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RequestMapping("/bkge/user")
@RestController
public class CposBkUserController {

    @Autowired
    private CposBkUserMapper cposBkUserMapper;

    //权限查询用户列表 分页显示
    @GetMapping("/selectCpUserList")
    @ResponseBody
    public ResultInfo selectCpUserList(Integer role, Integer currentPage, Integer currentCount) {

        ResultInfo resultInfo = new ResultInfo();

        if (role == null) {
            resultInfo.setMsg("权限为空");
            return resultInfo;
        }

        if (currentPage == null) {
            resultInfo.setMsg("当前页为空");
            return resultInfo;
        }

        if (currentCount == null) {
            resultInfo.setMsg("显示页为空");
            return resultInfo;
        }


        //创建分页对象
        // 传入当前页数 和显示数量
        Page<CposBkUser> page = new Page(currentPage, currentCount);
//        Page userPage = cposBkUserService.selectCposBkUserPage(page, role);
//        if(!userPage.equals("")){
//            resultInfo.setData(userPage);
//            resultInfo.setMsg("分页数据查询成功");
//        }else{
//            resultInfo.setMsg("分页查询数据为空");
//        }

        return resultInfo;

    }


    /*
     *   插入方法
     * */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResultInfo insert(@RequestBody CposBkUser cposBkUser) {

        ResultInfo resultInfo = new ResultInfo();
        Integer insert = cposBkUserMapper.insert(cposBkUser);

        if (insert == 0) {
            resultInfo.setMsg("添加失败");
        } else {
            resultInfo.setMsg("添加成功");
        }
        return resultInfo;
    }


}
